package cuongnh.project.japanesediary.vocabulary.ui.wizard;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cuongnh.project.japanesediary.vocabulary.common.CommonServices;
import cuongnh.project.japanesediary.vocabulary.model.Kanji;
import cuongnh.project.japanesediary.vocabulary.ui.wizard.page.NewKanjiWizardPage;

@Component("newKanjiWizard")
@Scope("prototype")
public class AddKanjiWizard extends Wizard implements INewWizard {

	private Kanji kanji;
	private NewKanjiWizardPage page;
	private IWorkbench workbench;

	@Autowired
	private CommonServices commonServices;

	public AddKanjiWizard() {
		setWindowTitle("New Wizard");
		this.kanji = new Kanji();
	}

	public AddKanjiWizard(CommonServices commonServices,
			Kanji kanji) {
		setWindowTitle("New Wizard");
		this.kanji = kanji;
		this.commonServices = commonServices;
	}

	@Override
	public void addPages() {
		page = new NewKanjiWizardPage(kanji);
		addPage(page);
	}

	@Override
	public boolean performFinish() {
		commonServices.getKanjiDao().saveOrUpdate(kanji);
		return true;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench;

	}
	
	public Kanji getKanji() {
		return kanji;
	}

}
